import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import molle from "./molle.js";

export default new Vuex.Store({
  modules: {
    molle
  },
  state: {
    TOKEN: null
  },
  getters: {
    getValue: state => key => {
      return state[key];
    },
    getTOKEN: state => {
      if (state.TOKEN === null) {
        state.TOKEN = localStorage.getItem("TOKEN") || null;
      }
      return state.TOKEN;
    }
  },
  mutations: {
    //this.$store.commit('setValue',{key:'msg',value:'a'})
    setValue: (state, obj) => {
      state[obj.key] = obj.value;
    },
    setLocal: (state, value) => {
      state.key = value;
      localStorage.setItem("key", value);
    }
  },
  actions: {}
});
